package com.goldcn.order.controller;

import com.goldcn.order.dto.BankSettleDto;
import com.goldcn.order.dto.OrderCountDto;
import com.goldcn.order.dto.UserIDOrderByDto;
import com.goldcn.order.model.CountOrder;
import com.goldcn.order.service.CountOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by 1111 on 2016/12/8.
 */
@RestController
@RequestMapping("/count")
@Api(value = "统计", description = "统计管理")
public class CountOrderController {
    @Autowired
    CountOrderService countOrderService;

    @ApiOperation(value = "新增订单统计")
    @RequestMapping(method = RequestMethod.POST)
    public Object addCountOrder(@RequestBody CountOrder countOrder) {
        return countOrderService.addCountOrder(countOrder);
    }

    @ApiOperation(value = "初始化总部和超级管理员订单统计")
    @RequestMapping(value = "/initOder/{companyID}", method = RequestMethod.GET)
    public Object addCountOrder(@PathVariable Long companyID) {
        return countOrderService.initCountOrder(companyID);
    }


    @ApiOperation(value = "按组织ID删除订单统计记录")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Object delteCountOrderByOID(@RequestBody Map<String, Object> params) {
        return countOrderService.delteCountOrderByOID(params);
    }

    @ApiOperation(value = "云管控、银行内部人员首页数据")
    @RequestMapping(value = "/homePage/{userID}/{companyID}", method = RequestMethod.GET)
    public Object selectBankHomePageData(@PathVariable Long userID, @PathVariable Long companyID) {
        return countOrderService.selectBankHomePageData(userID, companyID);
    }

    @ApiOperation(value = "下属部门或用户订单数据统计")
    @RequestMapping(value = "/subCount/{pageNum}/{pageSize}", method = RequestMethod.POST)
    public Object selectCountByDepartment(@PathVariable int pageNum, @PathVariable int pageSize, @RequestBody UserIDOrderByDto orderByDto) {
        return countOrderService.selectCountByDepartment(orderByDto, pageNum, pageSize);
    }

    @ApiOperation(value = "定时任务每日订单数据统计")
    @RequestMapping(value = "/updateCount", method = RequestMethod.GET)
    public Object updateCountOrder() {
        return countOrderService.updateCountOrder(null, null);
    }

    @ApiOperation(value = "定时任务每日订单数据统计【手动传入时间】")
    @RequestMapping(value = "/updateCount/{startTime}/{endTime}", method = RequestMethod.GET)
    public Object updateCountOrderByTime(@PathVariable Long startTime, @PathVariable Long endTime) {
        return countOrderService.updateCountOrder(startTime, endTime);
    }

    /**
     * @ApiOperation(value = "定时任务每日分类订单数据统计")
     * @RequestMapping(value = "/countClassify",method = RequestMethod.GET)
     * public Object insertCountClassify(){
     * return countOrderService.insertCountClassify();
     * }
     */

    @ApiOperation(value = "根据List<oIDOrUserID>,type 来查询对应的销售额，会员统计需求")
    @RequestMapping(value = "/IDList/{type}", method = RequestMethod.POST)
    public Object getTransactionByList(@RequestBody List<Long> IDList, @PathVariable int type) {
        return countOrderService.getTransactionByList(IDList, type);
    }

    @ApiOperation(value = "分类、订单金额趋势查询type【0 startTime，endTime自选，1最近七天，2最近一月，3最近三月】")
    @RequestMapping(value = "/classifyAmountTred/{type}", method = RequestMethod.POST)
    public Object getTransactionClassifyCountTred(@RequestBody OrderCountDto orderCountDto, @PathVariable int type) {
        return countOrderService.getTransactionClassifyCountTred(orderCountDto, type);
    }

    @ApiOperation(value = "商品销量统计")
    @RequestMapping(value = "/goodsSales/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object getGoodsSales(@PathVariable int pageNum, @PathVariable int pageSize) {
        return countOrderService.getGoodsSales(pageNum, pageSize);
    }

    @ApiOperation(value = "银行扣点金额统计[查总行，则branchID传1]")
    @RequestMapping(value = "/commission/{branchID}", method = RequestMethod.GET)
    public Object getCommission(@PathVariable Long branchID) {
        if (branchID == 1) {
            branchID = null;
        }
        return countOrderService.getTotalCommission(branchID);
    }

    @ApiOperation(value = "仅仅查询本部的订单、交易额统计数据")
    @RequestMapping(value = "/selfInfo/{userID}", method = RequestMethod.GET)
    public Object getSelfInfo(@PathVariable Long userID) {
        return countOrderService.getSelfInfo(userID);
    }

    /*-------------------------------------银行账单------------------------------------------*/
    @ApiOperation(value = "查询部门待核对、已核对数据")
    @RequestMapping(value = "/bankTotal/{oID}", method = RequestMethod.GET)
    public Object getSettleTotal(@PathVariable String oID) {
        return countOrderService.getSettleTotal(oID, null);
    }

    @ApiOperation(value = "根据分行or总行ID来查询有待核对数据的月份数据")
    @RequestMapping(value = "/bankData/{oID}", method = RequestMethod.GET)
    public Object getSettleData(@PathVariable String oID) {
        return countOrderService.getSettleData(oID, null);
    }

    @ApiOperation(value = "根据分行or总行ID、年、月来核对确认(总行的OID传0)")
    @RequestMapping(value = "/bankSettle", method = RequestMethod.POST)
    public Object getBankSettle(@RequestBody BankSettleDto bankSettleDto) {
        return countOrderService.getBankSettle(bankSettleDto);
    }

    @ApiOperation(value = "根据银行ID、年、月查询银行本部及其下属交易额、中收额(1包含待核对查询 2已核对查询)")
    @RequestMapping(value = "/bankSettleTotal/{type}", method = RequestMethod.POST)
    public Object getBankSettleTotal(@RequestBody BankSettleDto bankSettleDto, @PathVariable int type) {
        return countOrderService.getBankSettleTotal(bankSettleDto, type, 1);
    }

    @ApiOperation(value = "根据银行ID、年、月仅查询银行本部交易额、中收额")
    @RequestMapping(value = "/bankSettleTotalSelf/{type}", method = RequestMethod.POST)
    public Object getBankSettleTotal1(@RequestBody BankSettleDto bankSettleDto, @PathVariable int type) {
        return countOrderService.getBankSettleTotal(bankSettleDto, type, 2);
    }

    @ApiOperation(value = "根据银行ID、年、月查询银行本部及其下级部门对账单(1包含待核对查询 2已核对查询)")
    @RequestMapping(value = "/bankSettleList/{type}/{pageNum}/{pageSize}", method = RequestMethod.POST)
    public Object getBankSettlementList(@RequestBody BankSettleDto bankSettleDto, @PathVariable int type, @PathVariable int pageNum, @PathVariable int pageSize) {
        return countOrderService.getBankSettlementList(bankSettleDto, type, pageNum, pageSize);
    }

    @ApiOperation(value = "根据部门ID查询部门账单列表按供应商分")
    @RequestMapping(value = "/bankSettleSeller/{oID}/{year}/{month}", method = RequestMethod.GET)
    public Object getOrderSettleSellerList(@PathVariable Long oID, @PathVariable Integer year, @PathVariable Integer month) {
        return countOrderService.getBankSettleListGroupSeller(oID, year, month);
    }

    @ApiOperation(value = "根据部门ID查询本部门账单列表按供应商分(只查询本部门)")
    @RequestMapping(value = "/getBankSettleSellerSelf/{oID}/{year}/{month}", method = RequestMethod.GET)
    public Object getOrderSettleSellerListSelf(@PathVariable Long oID, @PathVariable Integer year, @PathVariable Integer month) {
        return countOrderService.getBankSettleSellerListSelf(oID, year, month);
    }

    @ApiOperation(value = "根据供应商ID、分行or总行ID来查询有待核对数据的月份数据")
    @RequestMapping(value = "/bankDataToSeller/{oID}/{supplierID}", method = RequestMethod.GET)
    public Object getSettleDataToSeller(@PathVariable String oID, @PathVariable Long supplierID) {
        return countOrderService.getSettleData(oID, supplierID);
    }

    @ApiOperation(value = "根据供应商ID、分行or总行ID来查询部门待核对、已核对数据")
    @RequestMapping(value = "/bankTotalToSeller/{oID}/{supplierID}", method = RequestMethod.GET)
    public Object getSettleTotalToSeller(@PathVariable String oID, @PathVariable Long supplierID) {
        return countOrderService.getSettleTotal(oID, supplierID);
    }
    /*-------------------------------------银行账单------------------------------------------*/


    /*-------------------------------------奖金对账单------------------------------------------*/
    @ApiOperation(value = "查询奖金待发放、已发放数据合计数。仅平台用户可以使用")
    @RequestMapping(value = "/bonusTotal/{oID}", method = RequestMethod.GET)
    public Object getBonusTotal(@PathVariable String oID) {
        return countOrderService.getBonusTotal(oID);
    }


    @ApiOperation(value = "查询公司奖金月份数据。仅平台用户可以使用")
    @RequestMapping(value = "/bonusData/{oID}", method = RequestMethod.GET)
    public Object getBonusSettleData(@PathVariable String oID) {
        return countOrderService.getBonusListByMonth(oID);
    }
}
